package com.guigu.Curriculum.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.guigu.Curriculum.utils.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
@Component
public class MyBatisPlusConfig implements MetaObjectHandler {
    LocalDateTime now = LocalDateTime.now();
    @Override
    public void insertFill(MetaObject metaObject) {


        Object courseGmtCreate = getFieldValByName("courseGmtCreate", metaObject);
        if(courseGmtCreate==null){
            this.setFieldValByName("courseGmtCreate", now,metaObject);
        }
        this.setFieldValByName("courseGmtModified",now,metaObject);
        this.setFieldValByName("sortCreateTime",now,metaObject);
        this.setFieldValByName("sortUpdateTime",now,metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("courseGmtModified",now,metaObject);
        this.setFieldValByName("sortUpdateTime",now,metaObject);
    }
}
